/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.GUI.controls;

import ac.engin.engin.get_data;
import ac.ui.controls.PCLGetdata;
import ac.ui.controls.PCLGetdataFull;
import ac.ui.custemItmes;
import javax.swing.JFrame;

/**
 *
 * @author ismail
 */
public class getData1 extends ac.ui.controls.PCLFrame {

    public PCLGetdata parent;
    public String Type;
    public String Tabel;
    public PCLGetdataFull parentFull;

    get_data g = new get_data();

    /**
     * Creates new form getData1
     */
    public getData1(String type, String Tabel) {
        initComponents();

        getDataTree.setAddtype(type);

        getDataTree.updateData();

        this.Type = type;

        this.Tabel = Tabel;

        g.TabelString = this.Tabel;

        g.index = jtb_index;
        g.indexTitle = "Name";
        g.indexField = "name";

        g.indexUpdate();

        onLoad();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtb_index = new ac.ui.controls.PCLTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        getDataTree = new ac.ui.controls.PCLTree();
        pCLButton1 = new ac.ui.controls.PCLButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jtb_index.setType("index");
        jtb_index.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtb_indexMouseClicked(evt);
            }
        });
        jtb_index.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtb_indexKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtb_indexKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtb_indexKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jtb_index);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        getDataTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        getDataTree.setAddtype("");
        getDataTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                getDataTreeValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(getDataTree);

        pCLButton1.setType("add");
        pCLButton1.setText("jbt_add");
        pCLButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pCLButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addComponent(pCLButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pCLButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 218, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 478, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jtb_indexMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtb_indexMouseClicked
        //    jlb_indexinfo.setText(c.FrameDataupdate());
    }//GEN-LAST:event_jtb_indexMouseClicked

    private void jtb_indexKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtb_indexKeyTyped

    }//GEN-LAST:event_jtb_indexKeyTyped

    private void jtb_indexKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtb_indexKeyReleased
        //   jlb_indexinfo.setText(c.FrameDataupdate());
    }//GEN-LAST:event_jtb_indexKeyReleased

    private void jtb_indexKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtb_indexKeyPressed
        //    jlb_indexinfo.setText(  c.getkeyPressed( evt)) ;
    }//GEN-LAST:event_jtb_indexKeyPressed

    private void getDataTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_getDataTreeValueChanged

        String catid = getDataTree.getValue();
        if (!catid.equals("0")) {

            g.Where = "`cat_id`='" + catid + "'";
        } else {
            g.Where = "";
        }
        g.indexUpdate();

    }//GEN-LAST:event_getDataTreeValueChanged

    private void pCLButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pCLButton1ActionPerformed
        ac.ui.utils u = new ac.ui.utils();

        if (parent != null) {
            u.comBoxappend(parent, new String[]{jtb_index.getValue()}, new String[]{jtb_index.getText()});
            parent.repaint();
            ac.ui.utils.comBoxSetSelectonByValue(parent, jtb_index.getValue());

        }
        if (parentFull != null) {
            parentFull.updateData();

        }
        this.dispose();
    }//GEN-LAST:event_pCLButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(getData1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(getData1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(getData1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(getData1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new getData1("", "").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private ac.ui.controls.PCLTree getDataTree;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private ac.ui.controls.PCLTable jtb_index;
    private ac.ui.controls.PCLButton pCLButton1;
    // End of variables declaration//GEN-END:variables
}
